//
// Created by shao.liming on 2/2/2018.
//

#include <iostream>
#include "E245.h"

std::string E245::removeKZeros(std::string str, int k) {
    if (str.empty() || k < 1)
        return str;

    int count = 0;
    for (int i = 0; i < str.size(); ++i) {
         if (str[i] == '0'){
             count ++;
         }else{
             if (count == k){
                 str.erase(i-k, k);
                 i -= k;
             }
             count = 0;
         }
    }

    if (count == k)
        str.erase(str.end()-k, str.end());

    return str;
}

void E245::test() {
    std::string str = "A00B";
    std::string ret = removeKZeros(str, 2);
    std::cout << "Ret string is " << ret;

}
